<?php
/**
 * Created by PhpStorm.
 * User: Sixstar-Peter
 * Date: 2019/4/16
 * Time: 23:08
 */

$cid = go(function () {
    echo "co 1 start\n";
    for ($i = 0; $i < 10; $i++) {
        echo $i . PHP_EOL;
        //在不会产生io的情况下主动让出
        if ($i == 5) {
            Co::yield(); //主动让出执行
        }
    }
    echo "co 1 end\n";
});

go(function () use ($cid) {
    echo "co 2 start\n";
    co::sleep(0.5);
    co::resume($cid);//恢复
    echo "co 2 end\n";
});